package com.ti.demo.autoconfigure.log;

import lombok.AllArgsConstructor;
import org.zalando.logbook.*;

import java.io.IOException;

/**
 * @description: biz日志打印
 * @Author Triagen
 * @Date 2025/4/14 16:48
 */
@AllArgsConstructor
public class AccSink implements Sink {

    private final ReqRspHttpLogFormatter formatter;

    private final HttpLogWriter writer;

    @Override
    public boolean isActive() {
        return writer.isActive();
    }

    @Override
    public void write(final Precorrelation precorrelation, final HttpRequest request) throws IOException {
    }

    @Override
    public void write(final Correlation correlation, final HttpRequest request, final HttpResponse response)
            throws IOException {
        writer.write(correlation, formatter.format(correlation, request, response));
    }
}
